/**
 * 开票管理
 * 2017年11月22日15:38:45
 * FizzPang
 * **/

$(function () {
    wzERP.Common.inlineDate('#applystart', '#applyend');  //联动日期搜索日期
    wzERP.Common.singleDate('#makeInvoiceDatePar');          //开票日期
})
//var preurl='http://localhost:9596'; //测试地址
var preurl='';
var vm = new Vue({
        el: "#main",
        data: {
            show_apply_tab: true,//是否显示申请tab
            searchForm: {
                keyword: '',//关键字
                customerType: 0,//客户类型
                apply_starttime: '',//申请开始时间
                apply_endtime: '',//申请结束时间
                status: '',//状态
            },
            applyStatus: [
                {code: 0, name: '全部'},
                {code: 1, name: '待提交'},
                {code: 2, name: '待审核'},
                {code: 3, name: '代开票'}
            ],
            finishStatus: [
                {code: 0, name: '全部'},
                {code: 4, name: '已开票'},
                {code: 5, name: '已作废'},
            ],
            customerType: [
                {code: 0, name: '签约客户'},
                {code: 1, name: '合作商'},
            ],
            apply_table_display: 10,
            finish_table_display: 10,
            apply_table: {},//申请列表数据
            finish_table: {},//已开发票数据
            modal: {
                showApplyDailog: false,//控制发票编辑弹窗
                applyDilogTitle: '申请开票',   //弹窗标题
                applyDetailDailog: false,//控制申请开票详情
                detailApplyTitle: '申请开票详情', //申请弹窗标题
                createInvoiceDialog:false,//开票弹窗
                invoiceDetailDialog:false,//开票详情弹窗
            },
            applyForm: {
                id:'',//主键id
                applyPerson: '',//申请人
                custId: '',//客户id
                custName: '',//	客户名称
                invoiceType: '1',//	发票类型
                taxCode: '',//	纳税人识别号
                registAddr: '',//注册地址
                registPhone: '',//注册电话
                invoiceUserName: '',//银行账户
                taxProveUrl: '',//	一般纳税人证明
                invoiceHeaderId: '0',//发票抬头id
                openBank: '',//开户行
                headerName: '',//发票抬头名称
                valoremTotal: 0.00,//	发票金额
                personPhone: '',//联系电话
                person: '',//联系人
                personAddr: '',//联系地址
                remark: ''//备注
            },
            showInvoiceSpecial: true,//是否显示专用发票表单内容
            customerList: [],//客户列表用于申请开票
            applyDetailType: "detail",//控制详情弹窗的内容 //detail:详情;auditing:审核;
            headNameList: [],//发票抬头列表
            headOrderList: [],//待开订单列表
            invoicelog: [],    //操作日志
            showCustomerRes:false,//是否显示客户搜索结果
            invoiceList:[{invoiceCode:'',invoiceType:'1',imageUrl:'',status:'0'}],
            expressCompanyList:[
                {name:'中通'},
                {name:'圆通'},
                {name:'顺丰'},
                {name:'EMS'},
                {name:'京东'},
                {name:'韵达'}
            ]//快递公司

        },
        //初始化
        mounted: function () {
            this.getApplyData(1);
            this.getFinishData(1);
            // this.getExpressCompany();
        },
        methods: {
            //前往申请tab
            to_apply_tab: function () {
                this.show_apply_tab = true;
            },
            //前往已完成tab
            to_finish_tab: function () {
                this.show_apply_tab = false;
            },
            //点击搜索
            clickSearchApplyData: function () {
                if (this.show_apply_tab) {
                    this.getApplyData(1);
                } else {
                    this.getFinishData(1);
                }
            },
            //获取搜索条件
            getSearchForm: function () {
                var _this = this;
                var returnObj = {
                    searchKey: _this.searchForm.keyword,                 //关键字
                    custType: _this.searchForm.customerType,       //客户类型
                    startDate1: _this.$refs.applyStartTime.value, //申请开始时间
                    endDate1: _this.$refs.applyEndTime.value,     //申请结束时间
                    status: _this.searchForm.status,                   //状态
                }
                return returnObj;
            },
            //点击开票
            createInvoice:function (id) {
                var _this=this;
                this.$refs.makeInvoiceDate.value="";
                this.$refs.invoiceExpress.value="0";
                this.$refs.expressNo.value="";
                this.$refs.makeinvoiceRemark.value="";
                this.invoiceList=[{invoiceCode:'',invoiceType:'1',imageUrl:'',status:'0'}];

                this.modal.createInvoiceDialog=true;
                this.resetApplyDialogForm();
                this.getApplyDetailData(id);
            },
            //获取快递公司expressCompanyList
            getExpressCompany:function () {
                var _this=this;
              axios.get(preurl+'/finance/erpInvoiceManage/queryExpressCompany').then(function (res) {
                  if(res.data.code==0){
                      _this.expressCompanyList=res.data.data;
                  }else{
                      layer.msg(res.data.msg,{time:1000})
                  }
              })
            },

            //获取申请数据
            getApplyData: function (pageIndex) {
                pageIndex = pageIndex || 1;
                var _this = this;
                var params = _this.getSearchForm();
                params.current = pageIndex;
                params.pageSize = _this.apply_table_display;
                params.invoiceFlag=0;
                axios.post(preurl+'/finance/erpInvoiceManage/queryApplyPageHtml', VUE_UTIL.buildPostFormData(params)).then(function (res) {
                    _this.apply_table = res.data.data;
                    //主动调取检查权限按钮方法
                    _this.$nextTick(function () {
                       permissonHandler();
                    });
                    layui.use(['laypage', 'layer'], function () {
                        var laypage = layui.laypage;
                        laypage({
                            cont: 'apply-turn-page',
                            curr: pageIndex || 1,
                            pages: _this.apply_table.pages,
                            skin: '#457fe6',
                            skip: true,
                            jump: function (obj, first) {
                                if (!first) {
                                    var num = _this.dropdownContent(_this.$refs.applyDisplayNumber)
                                    _this.getApplyData(obj.curr);
                                }
                            }
                        })
                    })
                })
            },
            methodApplyName: function () {
                var num = this.dropdownContent(this.$refs.applyDisplayNumber);
                this.apply_table_display = num;
                this.getApplyData(1)
            },
            dropdownContent: function (item) {
                var index = item.selectedIndex
                index = index == -1 ? 0 : index;
                if (item.options[index].value == '全部') {
                    return ''
                } else if (item.options[index].value == '每页显示条数') {
                    return 10
                } else {
                    return item.options[index].value
                }
            },
            //申请开票
            clickAddApply: function () {
                this.$refs.search_customer.disabled=false;
                this.modal.showApplyDailog = true;
                this.modal.applyDilogTitle = '申请开票';
                this.resetApplyDialogForm();
            },
            //添加票据
            addInvoiceItem:function () {
                this.invoiceList.push({invoiceCode:'',invoiceType:'1',imageUrl:'',status:'0'});
            },
            //取消或删除一行
            deleInvoiceItem:function (item) {
                this.invoiceList.splice(item,1);
            },
            //保存一行发票
            saveInvoiceItem:function (item) {
                if(!item.invoiceCode){
                    layer.msg("请填写发票编号",{time:1000})
                    return
                }
                if(!item.imageUrl){
                    layer.msg("请上传发票电子档",{time:1000})
                    return
                }
                item.status=1;
            },
            //编辑一行发票
            eidtInvoiceItem:function (item) {
                item.status=0;
            },
            //改变发票的上传文件
            changeInvoiceFile:function (even) {
                var evenTarget=even.target;
                var _this=this
                var maxSize = 2 * 1024 * 1024;//最大容量 pdf,jpg,png,gif
                if(evenTarget.value){
                    if (evenTarget.files[0].size > maxSize || ['pdf','jpg','png','gif'].indexOf(evenTarget.value)>-1) {
                        layer.msg('请上传2Mb以内的pdf,jpg,png,gif文件', {time: 1000});
                        return false;
                    }
                    $(evenTarget).parent("form").ajaxSubmit({
                        type: 'POST',
                        success: function (result) {
                            if (result.code == 0) {
                                var filePath = result.data.filePath;
                                var fileName = result.data.fileName;
                                _this.invoiceList[evenTarget.getAttribute("index")].imageUrl=filePath;
                                evenTarget.nextElementSibling.innerText=fileName;
                                layer.msg('上传成功!', {time: 1000});
                            }else{
                                layer.msg(result.msg, {time: 1000});
                                return false;
                            }
                        }
                    });
                }else{
                    layer.msg("请上传发票电子档",{time:1000});
                    return false;
                }
            },
            //保存开票数据
            saveMakeInvoice:function () {
              var makeDate=this.$refs.makeInvoiceDate.value;
              var invoiceExpress=this.$refs.invoiceExpress.value;
              var expressNo=this.$refs.expressNo.value;
              var makeinvoiceRemark=this.$refs.makeinvoiceRemark.value;
              var _this=this;
              var sendData={
                  id:_this.applyForm.id,
                  invoiceDate:makeDate,
                  courierCompany:invoiceExpress,
                  courierNumber:expressNo,
                  invoiceremark:makeinvoiceRemark,
                  invoicetailList:_this.invoiceList
              }
              axios.post('/finance/erpInvoiceManage/invoiceApplyMeg',sendData).then(function (res) {
                  if(res.data.code==0){
                      layer("操作成功",{time:1000})
                      _this.modal.showApplyDailog = true;
                      _this.getApplyData(1);

                  }else{
                      layer.msg(res.data.msg,{time:1000});
                  }
              })
            },
            //查看开票详情
            showMakeInvoiceDetil:function (id) {
                var _this=this;
                axios.get('/finance/erpInvoiceManage/findOpneInvoiceDetailById?id='+id).then(function (res) {
                    if(res.data.code==0){
                        _this.modal.invoiceDetailDialog=true;
                        var fishData=res.data.data;
                        _this.applyForm.applyDatetime=fishData.applyDate;
                        _this.applyForm.applyPerson=fishData.createUserName;
                        _this.applyForm.custName=fishData.custName;
                        _this.applyForm.invoiceMoney=fishData.invoiceMoney;
                        _this.applyForm.hearName=fishData.headerName;
                        _this.applyForm.invoiceType=fishData.invoiceType;
                        _this.applyForm.invoiceDate=fishData.invoiceDate;
                        _this.applyForm.courierCompany=fishData.courierCompany;
                        _this.applyForm.courierNumber=fishData.courierNumber;
                        _this.applyForm.invoiceUserName=fishData.invoiceUserName;
                        _this.applyForm.remark=fishData.remark;
                        _this.invoiceList=fishData.invoiceFileVOList;

                    }else{
                        layer.msg(res.data.msg,{time:1000})
                    }
                })
            },
            //点击编辑
            clickEditDetail:function (custType,custId,invoiceManageId,status) {
                this.modal.showApplyDailog = true;
                this.modal.applyDilogTitle = '编辑开票';
                this.resetApplyDialogForm();
                var _this=this;

                //获取发票抬头列表
                function callback(data) {

                    _this.applyForm.custId=custId;
                    _this.applyForm.custType=custType;
                    _this.applyForm.custName=data.custName;
                    _this.applyForm.invoiceHeaderId=data.invoiceHeaderId
                    _this.applyForm.person=data.contacter
                    _this.applyForm.personPhone=data.contactPhone
                    _this.applyForm.contactAdd=data.contactAdd
                    _this.applyForm.remark=data.remark
                    _this.headOrderList=data.invoiceManageDetail;
                    _this.headNameList=data.invoiceHeaderManage;
                    _this.applyForm.invoiceManageId=invoiceManageId
                    _this.applyForm.id=invoiceManageId
                    _this.applyForm.valoremTotal=data.invoiceMoney/100
                    _this.setSelectHeadName(data.invoiceHeaderId);
                    _this.$refs.search_customer.disabled=true;
                    _this.applyForm.invoiceType=data.invoiceType
                    $($(".invoicetype")[data.invoiceType]).click();
                    _this.headOrderList.forEach(function (t) {
                        t.bcMoney=t.bcMoney/100
                    })

                    // document.querySelectorAll('[name=invoicetype]')[data.invoiceType].setAttribute("checked",true);
                };
                this.preEditGetApplyDeatil(custType,custId,invoiceManageId,status,callback);
            },
            //自动搜索客户
            autoSearchCustomer: function () {
                var keyWord = this.$refs.search_customer.value
                var type = document.querySelector("#search_customerType").value
                if(!keyWord){
                    return
                }
                var _this = this;
                axios.get(preurl+'/finance/erpAccountReceivable/findCustGroupList?custName=' + keyWord + '&custType=' + type).then(function (res) {
                    if (res.data.code == 0) {
                        _this.customerList = res.data.data;
                        _this.showCustomerRes=true;

                    } else {
                        layer.msg(res.data.msg, {time: 1000})
                    }
                })
            },
            searchBlur:function(){
                this.showCustomerRes=false;
            },
            saveApplyForm: function (status) {
                var _this = this;
                var sendData = {
                    invoiceManageId:_this.applyForm.id,
                    custType:document.querySelector("#search_customerType").value,
                    custId:_this.applyForm.custId,
                    custName: _this.applyForm.custName,
                    invoiceHeaderId: _this.applyForm.invoiceHeaderId,
                    invoiceType: document.querySelector('[name=invoicetype]:checked').value,
                    headerName: _this.applyForm.headerName,
                    invoiceMoney: _this.applyForm.valoremTotal*100,
                    flag: status,
                    remark: _this.applyForm.remark,
                    invoiceManageDetail: _this.headOrderList,
                }
                _this.headOrderList.forEach(function (t) {
                    t.bcMoney=t.bcMoney*100
                })

                if(sendData.invoiceManageId){
                    sendData.option=1;
                }else{
                    sendData.option=0;
                }

                if(sendData.invoiceType==1){
                    sendData.contactPhone=_this.applyForm.personPhone
                    sendData.contactAdd=_this.applyForm.contactAdd
                    sendData.contacter= _this.applyForm.person
                }

                if(!sendData.custId){
                    layer.msg("请选择客户",{time:1000});
                    return
                }
                if(!sendData.invoiceHeaderId){
                    layer.msg("请选择发票抬头",{time:1000});
                    return
                }
                if(!sendData.invoiceMoney){
                    layer.msg("请填写本次开票金额",{time:1000});
                    return
                }
                console.log(sendData);

                axios.post(preurl+'/finance/erpInvoiceManage/applyInvoiceSaveMsg', sendData).then(function (res) {
                    if (res.data.code == 0) {
                        layer.msg("操作成功",{time:1000})
                        _this.closeApplyDialog();
                        _this.getApplyData(1);
                    } else {
                        layer.msg(res.data.msg, {time: 1000})
                    }
                })

            },
            //关闭开票弹窗
            closeApplyDialog: function () {
                this.modal.showApplyDailog = false;
            },
            //重置表单
            resetApplyDialogForm: function () {
                this.applyForm.id='';
                this.applyForm.applyPerson = ''//申请人
                this.applyForm.custId = ''//客户id
                this.applyForm.custType = 0//客户id
                this.applyForm.custName = ''//	客户名称
                this.applyForm.invoiceType = '1'//	发票类型
                this.applyForm.orderCode = ''//	订单编号
                this.applyForm.taxCode = ''//	纳税人识别号
                this.applyForm.registAddr = ''//注册地址
                this.applyForm.registPhone = ''//注册电话
                this.applyForm.invoiceUserName = ''//银行账户
                this.applyForm.taxProveUrl = ''//	一般纳税人证明
                this.applyForm.invoiceHeaderId = '0'//发票抬头id
                this.applyForm.openBank = ''//开户行
                this.applyForm.headerName = ''//发票抬头名称
                this.applyForm.accountReceivableCode = ''//应收账款编号
                this.applyForm.billDatetime = ''//应收款日期
                this.applyForm.valoremTotal = 0.00//	发票金额
                this.applyForm.remark = ''//	备注
                // this.applyForm.wkMoney = ''//未开金额
                // this.applyForm.bcMoney = ''//	本次开票金额
                this.headNameList = [];
                this.headOrderList = [];
                this.applyForm.person="";
                this.applyForm.personPhone="";
                this.applyForm.personAddr="";
                this.$refs.search_customer.value="";

            },
            //显示详情
            showApplyDetil: function (id) {
                this.applyDetailType = "detail"
                this.modal.detailApplyTitle = "申请开票详情"
                this.modal.applyDetailDailog = true;
                this.getApplyDetailData(id)
            },
            //编辑前获取详情
            preEditGetApplyDeatil:function(custType,custId,invoiceManageId,status,cb){
                var _this=this;
                var sendData={
                    custType:custType,
                    custId:custId,
                    invoiceManageId:invoiceManageId,
                    status:status
                }
                var geturl='/finance/erpInvoiceManage/queryInvoiceMsg'+VUE_UTIL.buildRequestParameters(sendData);
                axios.get(geturl).then(function (res) {
                    if(res.data.code==0){
                        if(cb && typeof  cb =='function'){
                            cb(res.data.data);
                        }
                    }else{
                        layer.msg(res.data.msg,{time:1000});
                    }
                })
            },
            //获取详情
            getApplyDetailData: function (id,cb) {
                var _this = this;
                axios.get(preurl+'/finance/erpInvoiceManage/editInvoiceManageDetail?id=' + id).then(function (res) {
                    if (res.data.code == 0) {
                        var finalData=res.data.data;
                        _this.applyForm.id=finalData.id;
                        _this.applyForm.applyDatetime = finalData.applyDate;
                        _this.applyForm.applyPerson = finalData.createUserName ?  finalData.createUserName :"";
                        _this.applyForm.custName = finalData.custName;
                        _this.applyForm.hearName = finalData.headerName ? finalData.headerName :"";
                        _this.applyForm.invoiceType = finalData.invoiceType;
                        _this.applyForm.taxCode = finalData.taxCode;
                        _this.applyForm.taxProveUrl = finalData.taxProveUrl;
                        _this.applyForm.registAddr = finalData.registAddr;
                        _this.applyForm.invoiceUserName = finalData.invoiceUserName;
                        _this.applyForm.openBank = finalData.openBank;
                        _this.applyForm.contacter = finalData.contacter;
                        _this.applyForm.contactPhone=finalData.contactPhone;
                        _this.applyForm.contactAdd=finalData.contactAdd;
                        _this.applyForm.invoiceMoney=finalData.invoiceMoney;
                        _this.applyForm.remark=finalData.remark;
                        _this.applyForm.openbankNumber=finalData.openbankNumber

                        _this.headOrderList = res.data.data.invoiceManageDetail
                        
                        // _this.invoicelog = res.data.data.invoicelog;
                        if(cb && typeof  cb =='function'){
                            cb(finalData);
                        }

                    }
                })
            },
            //搜索客户
            searchCustomer: function () {
                this.autoSearchCustomer()
            },
            //隐藏搜素结果
            hideSearchCuRes:function () {
                this.showCustomerRes=false;
            },
            //确定选中某个用户
            confirmCustomer: function (item,seleid) {
                this.showCustomerRes=false;
                document.querySelector("#searchCusRes").classList.add('hide');
                this.$refs.search_customer.value=item.custName
                this.applyForm.custId = item.custId;
                this.applyForm.custName=item.custName
                var custType=document.querySelector("#search_customerType").value
                var _this = this;
                axios.get(preurl+'/finance/erpInvoiceManage/queryInvoiceMsg?custId='+item.custId+"&custType="+custType).then(function (res) {
                    if (res.data.code == 0) {
                        if(res.data.data.invoiceHeaderManage && res.data.data.invoiceHeaderManage.length>0){
                            _this.headNameList = res.data.data.invoiceHeaderManage;
                            if(seleid){
                                _this.setSelectHeadName(seleid);
                            }else{
                                _this.setSelectHeadName('default');
                                _this.headOrderList = res.data.data.invoiceManageDetail
                            }
                        }else{
                            layer.msg("该客户还没有配置发票抬头",{time:1000})
                        }
                    } else {
                        layer.msg(res.data.msg, {time: 1000})
                    }
                })
            },
            //修改发票金额
            getTotalInvoiceMoney:function(){
                var _this=this;
                _this.applyForm.valoremTotal=0.00;
                this.headOrderList.forEach(function (item) {
                    item.bcMoney=item.bcMoney ? item.bcMoney : 0;
                    if(item.bcMoney<0){
                        layer.msg("开票金额必须大于等于0",{time:1000})
                        return
                    }
                    _this.applyForm.valoremTotal=parseFloat(_this.applyForm.valoremTotal,10)+parseFloat(item.bcMoney,10)
                });
            },
            //设置一个发票抬头 str:default 默认;id;
            setSelectHeadName: function (str) {
                var getItem = {};
                var _this = this;
                for (var i = 0; i < _this.headNameList.length; i++) {
                    var item =_this.headNameList[i];
                    if (str == 'default') {
                        if (item.isDefault == 1) {
                            getItem = item
                            break;
                        }
                    } else {
                        if (item.id == str) {
                            getItem = item
                            break;
                        }
                    }
                }
                _this.$refs.select_headname.value=getItem.id;
                _this.applyForm.invoiceHeaderId = getItem.id    //发票抬头id
                _this.applyForm.headerName = getItem.headerName  //发票抬头名称
                _this.applyForm.invoiceType = getItem.invoiceType//	发票类型
                _this.applyForm.taxCode = getItem.taxCode       //	纳税人识别号
                _this.applyForm.taxProveUrl = getItem.taxProveUrl//	一般纳税人证明
                _this.applyForm.registAddr = getItem.registAddr
                _this.applyForm.registPhone = getItem.registPhone
                _this.applyForm.invoiceUserName = getItem.invoiceUserName
                _this.applyForm.openBank = getItem.openBank

            },
            //改变客户的发票抬头
            changeHeaderName: function () {
                var id = this.$refs.select_headname.value;
                this.setSelectHeadName(id);
            },
            //作废
            discardInvoice:function (id) {
                var _this=this;
                layer.confirm("确定作废吗?", function (index) {
                    layer.close(index);
                    axios.get('/finance/erpInvoiceManage/updateInvoiceDiscard?id=' + id ).then(function (res) {
                        if (res.data.code == 0) {
                            layer.msg('操作成功', {time: 1000})
                            _this.getFinishData(1);
                        } else {
                            layer.msg(res.data.msg, {time: 1000})
                        }

                    })
                })
            },
            changeStatus: function (id, status) {
                var _this = this;
                var str = "确定要删除该申请吗?"
                var posturl="/finance/erpInvoiceManage/applyStatus?manageId="+id;//提交申请
                if (status == 0) {
                    str = "确定提交该申请吗?"
                } else if (status == 1) {
                    str = "确定删除该申请吗?"
                    posturl="/finance/erpInvoiceManage/editStatus?manageId="+id;//删除申请
                }

                layer.confirm(str, function (index) {
                    layer.close(index);
                    axios.get(posturl).then(function (res) {
                        if (res.data.code == 0) {
                            layer.msg('操作成功', {time: 1000})
                            _this.getApplyData(1);
                        } else {
                            layer.msg(res.data.msg, {time: 1000})
                        }

                    })
                })
            },
            //点击审核按钮
            toAuditing: function (id) {
                this.applyDetailType = "auditing";
                this.resetApplyDialogForm();
                // document.querySelector("[name=auditingStatus]:checked").checked=false
                this.$refs.auditingremark.value="";
                this.modal.detailApplyTitle = "申请开票审核"
                this.getApplyDetailData(id);
                this.modal.applyDetailDailog = true;

            },
            //保存审核
            auditing:function () {
                var invoiceId=this.applyForm.id;
                var status=document.querySelector("[name=auditingStatus]:checked").value;
                var remark=this.$refs.auditingremark.value;
                var _this=this;
                axios.post('/finance/erpInvoiceManage/invoiceStatusUpdate',{invoiceManageId:invoiceId,status:status,auditRemark:remark}).then(function (res) {
                    if(res.data.code==0){
                        layer.msg("操作成功",{time:1000})
                        _this.modal.applyDetailDailog = false;
                        _this.getApplyData(1);
                    }else{
                        layer.msg(res.data.msg,{time:1000})
                    }
                })
            },
            /********已开发票tab方法******/
            //获取已开发票数据
            getFinishData: function (pageIndex) {
                pageIndex = pageIndex || 1;
                var _this = this;
                var params = _this.getSearchForm();
                params.current = pageIndex;
                params.pageSize = _this.finish_table_display;
                params.invoiceFlag = 1;
                console.log("已开发票请求数据"+JSON.stringify(params));
                var geturl='/finance/erpInvoiceManage/findInvoiceOpenPage'+VUE_UTIL.buildRequestParameters(params);
                axios.get(geturl).then(function (res) {
                    _this.finish_table = res.data.data;

                    //主动调取检查权限按钮方法
                    _this.$nextTick(function () {
                        permissonHandler();
                    });
                    layui.use(['laypage', 'layer'], function () {
                        var laypage = layui.laypage;
                        laypage({
                            cont: 'finish-turn-page',
                            curr: pageIndex || 1,
                            pages: _this.finish_table.pages || 1,
                            skin: '#457fe6',
                            skip: true,
                            jump: function (obj, first) {
                                if (!first) {
                                    var num = _this.dropdownContent(_this.$refs.finishDisplayNumber)
                                    _this.getFinishData(obj.curr);
                                }
                            }
                        })
                    })
                })
            },
            methodFinishName: function () {
                var num = this.dropdownContent(this.$refs.finishDisplayNumber);
                this.finish_table_display = num;
                this.getFinishData(1)
            },
        },
        //过滤器
        filters: {
            //将发票状态码转为文本
            getSattusText: function (value) {
                //状态:0：待提交，1：待审核 2：待开票 3：已开票 4：已作废 5：已拒绝 6:驳回
                var returnStr = "未知状态";
                switch (value) {
                    case 0:
                        returnStr = "待提交";
                        break;
                    case 1:
                        returnStr = "待审核";
                        break;
                    case 2:
                        returnStr = "待开票";
                        break;
                    case 3:
                        returnStr = "已开票";
                        break;
                    case 4:
                        returnStr = "已作废";
                        break;
                    case 5:
                        returnStr = "驳回";
                        break;
                }
                return returnStr;
            },
            //货币 分转为元
            getMoney:function (value) {
                if(!value || value==0){
                    return 0.00
                }
                return value/100;
            },
            //时间戳转字符串
            timeNumToDate:function(obj){
                var date =  new Date(obj);
                var y = 1900+date.getYear();
                var m = "0"+(date.getMonth()+1);
                var d = "0"+date.getDate();
                return y+"-"+m.substring(m.length-2,m.length)+"-"+d.substring(d.length-2,d.length);
            }
        },
        computed: {
            //获取总金额
            getTotalMoney: function () {
                var returnObj = {
                    orderTotalMoney: 0.00,
                    ykTotleMoney: 0.00,
                    wkTotleMoney: 0.00
                }
                for (var i = 0; i < this.headOrderList.length; i++) {
                    var item = this.headOrderList[i];
                    returnObj.orderTotalMoney += parseFloat(item.receiveAmount,10);
                    returnObj.ykTotleMoney += parseFloat(item.receivedAmount,10);
                    returnObj.wkTotleMoney += parseFloat(item.receivableBalance,10);
                }
                return returnObj;
            },
        },
        watch:{
            'applyForm.invoiceType':function(newValue,oldValue){
                if(newValue==1){
                    document.querySelectorAll('[name=invoicetype]')[1].checked=true;
                    this.showInvoiceSpecial=true;
                }else{
                    document.querySelectorAll('[name=invoicetype]')[0].checked=true;
                    this.showInvoiceSpecial=false
                }

            }
        }
    })
;